﻿using System.Windows.Shapes;
using System.Windows.Ink;
using System.Windows.Media;
using System.Windows;

namespace AzukiMapUI
{
    public class PalletRect 
    {
        int _num;
        byte _r;
        byte _g;
        byte _b;
        byte _a;
        string _name;
        string _nativeName;

        Rectangle _rect;

        public int Number
        {
            get { return _num; }
            set { _num = value; }
        }

        public byte R
        {
            get { return _r; }
            set
            {
                _r = value;
                SetFill();
            }
        }

        public byte G
        {
            get { return _g; }
            set
            {
                _g = value;
                SetFill();
            }
        }

        public byte B
        {
            get { return _b; }
            set
            {
                _b = value;
                SetFill();
            }
        }

        public byte A
        {
            get { return _a; }
            set
            {
                _a = value;
                SetFill();
            }
        }

        public string Name
        {
            get { return _name; }
            set { 
                _name = value;
                _rect.Resources.Add("Name", _name);
            }
        }

        public string NativeName
        {
            get { return _nativeName; }
            set {
                _nativeName = value;
                _rect.Resources.Add("NativeName", _nativeName);
            }
        }

        public double Width
        {
            get { return _rect.Width; }
            set { _rect.Width = value; }
        }

        public double Height
        {
            get { return _rect.Height; }
            set { _rect.Height = value; }
        }

        public Brush Stroke
        {
            get { return _rect.Stroke; }
            set { _rect.Stroke = value; }
        }

        public double StrokeThickness
        {
            get { return _rect.StrokeThickness; }
            set { _rect.StrokeThickness = value; }
        }

        public Thickness Margin
        {
            get { return _rect.Margin; }
            set { _rect.Margin = value; }
        }

        public Brush Fill
        {
            get { return _rect.Fill; }
        }

        public Rectangle Rect
        {
            get { return _rect; }
        }

        public PalletRect()
        {
            _num = 0;
            _r = 0;
            _g = 0;
            _b = 0;
            _a = 0;

            init();
        }

        public PalletRect(byte r, byte g, byte b, byte a)
        {
            _num = 0;
            _r = r;
            _g = g;
            _b = g;
            _a = a;

            init();
        }

        void init()
        {
            _rect = new Rectangle();
            _rect.StrokeThickness = 0.5;
            _rect.Stroke = new SolidColorBrush(Colors.Gray);
            _rect.Margin = new Thickness(2);
            _rect.Width = 12;
            _rect.Height = 12;

            SetFill();
        }

        void SetFill()
        {
            _rect.Fill = new SolidColorBrush(Color.FromArgb(_a, _r, _g, _b));
        }
    }

}
